<?php
class kst_mutasi_toko_model extends MY_Model {
	var $model = 'kst_mutasi_toko_model';
	
function petugas()
{
		$ls_sql	=  "SELECT	SUPPLIER_NAMA value,
							SUPPLIER_NAMA display
					FROM	ADMIN_PRIMKOKAS.KM_SUPPLIER
					ORDER BY SUPPLIER_ID";
					
		$result	= $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return array();
		}
}

function cabang()
{
		$ls_sql	=  "SELECT	CABANG_NAMA value,
							CABANG_NAMA display
					FROM	ADMIN_PRIMKOKAS.KM_CABANG
					ORDER BY CABANG_ID";
					
		$result	= $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return array();
		}
}

	function GetJSON()
	{
		$ls_sql	= "	SELECT	*
					FROM	kst_order_receive_toko2
					WHERE	(UPPER(receive_toko_id) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(supplier_nama) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(receive_toko_cabang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(receive_toko_no) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(receive_toko_tgl) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(receive_toko_gudang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(receive_toko_status) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'receive_toko_id' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode($this->paging($ls_sql) );
	}

	// function GetJSON2()
	// {
	// 	$ls_sql	= "	SELECT	
	// 						b.satuan_nama
	// 				FROM	km_barang a
	// 				INNER JOIN 		KM_SATUAN b ON a.satuan_id = b.satuan_id
	// 				WHERE	(UPPER(a.barang_nama) LIKE '%".strtoupper(post('keyword'))."%'
	// 						OR UPPER(a.barang_barcode) LIKE '%".strtoupper(post('keyword'))."%'
	// 						OR UPPER(a.barang_hpokok) LIKE '%".strtoupper(post('keyword'))."%'
	// 						OR UPPER(a.barang_hjual1) LIKE '%".strtoupper(post('keyword'))."%') 
	// 						ORDER BY ".(post('sort')=='' ? 'a.barang_nama' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	// 	return json_encode($this->paging($ls_sql) );
	// }

	function GetJSON2()
	{
		$ls_sql	= "	SELECT	*
					FROM	km_barang 
					WHERE	(UPPER(barang_nama) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(barang_barcode) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(barang_hpokok) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(barang_hjual1) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'barang_nama' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode($this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('kst_order_receive_toko2', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('kst_order_receive_toko2', $arr_data, $arr_rule);
	}

	function GetSingle($as_no_receive){
		$result = $this->db->get_where('kst_order_receive_toko2', array('receive_toko_id' => $as_no_receive));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function GetSingleView($as_no_receive)
	{
		$result = $this->db->get_where('kst_order_receive_toko2', array('receive_toko_id' => $as_no_receive));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM kst_order_receive_toko2 WHERE receive_toko_id = '".$arr_rule['receive_toko_id']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['receive_toko_id']."]<br />";
			}else{
				$this->db->delete('kst_order_receive_toko2', array('receive_toko_id' => $arr_rule['receive_toko_id']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>